package servlet;

import java.util.List;

import javabean.Factory;
import javabean.user.User;

import javax.servlet.RequestDispatcher;

public class UserInfoServlet extends BaseServlet{
	/**
	 * 
	 */
	private static final long serialVersionUID = -8538076142868886263L;
	
	public void service() throws Exception{
		String uid = (String) request.getSession().getAttribute("uid");
		if(uid!=null){
			List<User> all = null;
			try{
				all = Factory.getUserDAOInstance().queryAllByUidOrEmail(uid);
			}catch(Exception ex){}
			if(all.size()>0){
				User user = (User)all.get(0);
				request.setAttribute("user", user);
				//跳转
				RequestDispatcher dispatcher = request.getRequestDispatcher("/user/user_info.jsp");
				dispatcher.forward(request, response) ;
			}
		}else{
			//跳转
			RequestDispatcher dispatcher = request.getRequestDispatcher("/login");
			dispatcher.forward(request, response) ;
		}
	}
}
